//用户信息数据 包含两个用户信息列表
function createUserList() {
  return [
    {
      userId: 1,
      username: "admin",
      password: "111111",
      desc: "管理员",
      roles: ["平台管理员"],
      buttons: ["cuser.detail"],
      routes: ["home"],
      token: "1234567890",
    },
    {
      userId: 2,
      username: "system",
      password: "111111",
      desc: "编辑",
      roles: ["编辑"],
      buttons: ["cuser.detail"],
      routes: ["home"],
      token: "1234567890",
    },
  ];
}

// 对外暴露一个数组：包含两个接口

// 登录接口
// 获取用户信息假的接口
export default [
  {
    url: "/api/user/login",
    method: "post",
    response: ({ body }) => {
      const { username, password } = body;
      const checkUser = createUserList().find((item)=>item.username===username && item.password===password)
      if (!checkUser) {
        return {
          code: 201,
          data: {
            message: "用户名或密码错误",
          },
        };
      }else{
        const {token }= checkUser
        return {
          code: 200,
          data:{
            "token":token
          }
        };
      }
    },
  },
  {
    url: "/api/user/info",
    method: "get",
    response: (request) => {
      // 获取token
      const token = request.headers.token;
      // 获取用户信息
      const checkUser = createUserList().find((item) => item.token === token);
      if (!checkUser) {
        return {
          code: 201,
          data: {
            message: "用户名或密码错误",
          },
        };
      } else {
        return {
          code: 200,
          data: checkUser,
        };
      }
    },
  },
];
